import React, {Component} from 'react';
import ReactDOM from 'react-dom';
import {Card, PullToRefresh, Icon,ActivityIndicator} from 'weaver-mobile';
import {inject, observer} from 'mobx-react';
import TopTabs from './TopTabs';
import SignItem from './SignItem';
import base from "../../util/base";
import {toJS} from 'mobx';
import { showFormReq, getLabel} from '../../util/common';
import * as SignUtil from "../../util/SignUtil";
import Reply from './Reply';
@inject('wfSignListStore','secondAuthDetail')
@observer 
export default class Main extends Component {

    constructor(props) {
        super(props);
        this.signListRef = React.createRef();
    }

    componentDidMount() {
        const {wfSignListStore, params,reqUrlParams} = this.props;
        wfSignListStore.initLog(params,reqUrlParams);
    }

    componentWillUnmount(){
        const { wfSignListStore } = this.props;
        wfSignListStore.removeAllState();
    }

    componentDidUpdate() {
        const {wfSignListStore} = this.props;
        const {loglist} = wfSignListStore;
        const jQuery =  window.jQuery;
        loglist.length > 0 && window.formImgLazyLoad(jQuery(".wf-signList"));
    }

    render() {
        const {wfSignListStore} = this.props;
        const {tabKey} = base.wfGlobalStore;
        const {loglist, activeKey, requestLogParams = {}, queryLogParams, refReqInfo,loading = false} = wfSignListStore;
        return (
            <div className={`wf-signList ${tabKey == 'signlist' ? 'wf-signList-tab' :''}`}>
                <TopTabs/>
                <div className={`wf-signList-scrollContent ${tabKey == 'signlist' ? 'wf-signList-scrollContent-tab' :''}`} onScroll={()=>SignUtil.loadMoreSign()}>
                    { refReqInfo && this.getRefReqParams(refReqInfo)}
                    {this.getDataList(loglist)}
                    {loading && <ActivityIndicator text={''}/>}
                </div>
               
            </div>
        )
    }
    passReplyInfo = (info) => {
      this.setState({
        replyInfo: info
      })

    }
    //获取数据列表
    getDataList(data) {
      const {wfSignListStore} = this.props;
        const {tabKey} = base.wfGlobalStore;
        const wfOperateStore = base.wfOperateStore;
        const {rightMenu = {}} = wfOperateStore;
        const {forward = '0'} = rightMenu;
        const { setTabKey, setSignReply, comSetStoreState} = this.props;
        const {secondAuthDetail, params} = this.props;
        const { isOpenCommunication } = params;
        const endArr = data.map((item, index) => {
            const {logid, isProtected, checkSuccess, protectType} = item;
            secondAuthDetail.setCheckResult(logid, {isProtected, checkSuccess, protectType});
            return (
                <SignItem 
                  store={wfSignListStore} 
                  comSetStoreState={comSetStoreState} 
                  setTabKey={setTabKey} 
                  setSignReply={setSignReply} 
                  isOpenCommunication= {isOpenCommunication} 
                  info={item} 
                  tabKey={tabKey} 
                  forward={forward}
                  key={index} 
                  secondAuthDetail={secondAuthDetail}
                />
            )
        })
        return endArr;
    }

    getRefReqParams(refReqInfo){
        if(refReqInfo) {
            const {wfSignListStore} = this.props;
            const {activeKey,refRequestid} = wfSignListStore;
            let isrequest = '';
            let prefix  = ''
            if(activeKey ==  '3') {
                isrequest = '3';
                prefix = getLabel(21254,'主流程');
            }
            if(activeKey ==  '4'){
                isrequest = '2';
                prefix = getLabel(19344,'子流程');
            }
            if(activeKey ==  '5') {
                isrequest = '4';
                prefix = getLabel(21255,'平行流程');
            }
            const {requestid} = base.wfGlobalStore.commonParam;
            let refReqParams = { desrequestid: requestid, isrequest, requestid:refRequestid};
            const {requestname} = refReqInfo;
            return (
                <div className={'ref-req-info'}>
                    {prefix}
                    <a onClick={()=>showFormReq(refRequestid,refReqParams,"/req")}>{requestname}</a>
                    {getLabel(504,'意见')}
                </div>
            )
        }
    }
}